import Vue from 'vue'
import Vuex from 'vuex'
import cityTrafficNew from './state/cityTrafficNew'
import cityTrafficNewDetail from './state/cityTrafficNewDetail'
import getters from './getters'
import {dateFormat2, getYesterday} from '../utils/dateUtil'
Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    cityTrafficNew,
    cityTrafficNewDetail
  },
  getters,
  state: {
    isend: 0,
    navIndex: 0,
    list: [],
    range: {
      startRange: 1,
      endRange: 20
    },
    dayTime: {
      startTime: '',
      endTime: ''
    },
    yearTime: {
      startTime: '',
      endTime: ''
    },
    rangeTime: {
      start: '',
      end: ''
    },
    companyList: [],
    searchKeyWord: '',
    companySubno: {

    },
    centerCompanySubno: {

    },
    controlPage: {
      prevPage: false,
      nextPage: true
    },
    limitPageActive: 0,
    loading: '',
    /*
     下边的变量都是之前逻辑所需变量， 我也不知道什么意思， 傻逼产品做搜索要跳页面，跳回来数据不变， 需要存数据， 用缓存做也不是很好做
     有的页面跳过来要缓存有的不要， 也挺麻烦， 懒得写了， 反正代码也跟屎一样了
     */
    timetitle1: dateFormat2(getYesterday()),
    timetitle: getYesterday(),
    // --------------------------
    firstActive: 0,
    secondtActive: 0,
    thirdActive: 0,
    subcName: '',
    chooseobj: {},
    initFlag: 0,
    qingfenShowTime: {
      startTime: '',
      endTime: ''
    }
    
  },
  mutations: {
    setisend (state) {
      state.isend = 0
    },
    setnotend (state) {
      state.isend = 1
    },
    setNavIndex (state, index) {
      state.navIndex = index
    },
    setList (state, list) {
      state.list = list
    },
    setRange (state, range) {
      state.range = range
    },
    setDayTime (state, time) {
      state.dayTime = time
    },
    setYearTime (state, time) {
      state.yearTime = time
    },
    setLoading (state, load) {
      state.loading = load
    },
    SETTIMETITLE1 (state, time) {
      state.timetitle1 = time
    },
    SETTIMETITLE (state, time) {
      state.timetitle = time;
      // console.log('state.timetitle', state.timetitle);
    },
    SETFIRSTACTIVE (state, active) {
      state.firstActive = active
    },
    SETSECONDTACTIVE (state, active) {
      // console.log('SETSECONDTACTIVE', active);
      state.secondtActive = active
    },
    SETTHIRDACTIVE (state, active) {
      state.thirdActive = active
    },
    SETSUBCNAME (state, name) {
      state.subcName = name
    },
    SETCHOOSEDOBJ (state, obj) {
      state.chooseobj = obj
    },
    SETINITFLAG (state, flag) {
      state.flag = flag
    },
    CHANGESEARCHKEYWORD(state, str) {
      state.searchKeyWord = str;
      // console.log('state-searchKeyWord', state.searchKeyWord);
    },
    CHANGESUBNO(state, obj) {
      state.companySubno = obj;
    },
    CENTERCHANGESUBNO(state, obj) {
      state.centerCompanySubno = obj;
    },
    CHANGECONTROLPAGE(state, obj) {
      // console.log('CHANGECONTROLPAGE', obj);
      state.controlPage.prevPage = obj.prevPage;
      state.controlPage.nextPage = obj.nextPage;
    },
    CHANGELIMITPAGEACTIVE(state, flag) {
      // console.log('CHANGECONTROLPAGE', flag);
      state.limitPageActive = flag;
    },
    CHANGEQINGFENTIME(state, obj) {
      // console.log('清分的时间', obj);
      state.qingfenShowTime.startTime = obj.startTime;
      state.qingfenShowTime.endTime = obj.endTime;
    }
  }
})

export default store
